package com.webinsky.web.freemarker;

import com.webinsky.web.resource.StaticResource;

import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;

import java.io.File;
import java.io.IOException;

public class StaticConfiguration {

    private String templatePath;
    private String outputPath;
    private Configuration cfg;
    private String basePath;
    
    public StaticConfiguration(String basePath) {
        this.templatePath = getTemplateDirectory().getAbsolutePath();
        this.basePath = basePath;
    }

    public Configuration get() throws IOException {
        if (cfg == null) {
            cfg = new Configuration(Configuration.VERSION_2_3_22);
            cfg.setDirectoryForTemplateLoading(new File(templatePath));
            cfg.setDefaultEncoding("UTF-8");
            cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        }
        return cfg;
    }

    public File getTemplateDirectory() {
        File file = new File(basePath, "templates");
        return file;
    }

    public File getOutputDirectory() {
        File file = new File(basePath, "Manual");
        return file;
    }

}
